// Header File
// Created 11/19/2007; 5:54:07 PM

#ifndef __UNIT_H__
#define __UNIT_H__

#include "Globals.h"
#include "Constants.h"

//define the grades or ranks for health purposes
#define CONSCRIPT	20
#define REGULAR		30
#define VETERAN		40
#define ELITE			50

//defines the units indices
#define SETTLER 0
#define WARRIOR 1
#define PIKEMAN 2
#define HORSEMAN 3
#define KNIGHT 4
#define ARCHER 5
#define SWORDSMAN 6
#define RIFLEMAN 7
#define INFANTRY 8
#define CATAPULT 9
#define CANNON 10
#define TANK 11
#define ARMOR 12
#define MECH_INFANTRY 13
#define GALLEY 14
#define GALLEON 15
#define BATTLESHIP 16
#define BOMBER 17
#define FIGHTER 18

//defines whether a unit is a Settler
#define IsSettler(X) (X.type == SETTLER)

// Unit structure
typedef struct 
{
	char name[14];
	char pic;
	char moveMAX;
	char atk; //Attack factor (chance to score hit attacking)
	char def; //Defense factor (chance to score hit defending)
	int cost;
	char area, transport;
	char preq, obsolete;
} Unit;

Unit _units[19];

#ifndef INSTALL

typedef struct
{
	int x, y;
	char type;
	char hpFULL, hpCURR; //Hit points (damage x10 which can be taken before elimination)
	char moveCURR;
	char settlerAction;
	char settlerActionTime;
	bool isFortified;
	int xTarget, yTarget;
} _Unit;

////////////////////////////
// Unit Methods ////////////
////////////////////////////
void NewUnit(char civ, char typeUnit, int x, int y, char grade);
void RemoveUnit(char index, char civ);
void ActionUnit(char num);
void MoveUnit(char civ, char unit, int x[30], int y[30], int dist);
char GetUnitIndicesCursor(char *units);
char GetUnitIndicesAt(char *units, int x, int y);
char GetNumberOfUnitsAt(char civ, int x, int y);
char GetNumberOfUnitsCursor(char civ);
bool Explore(char civ, char unit);
void MoveRandom(char civ, char unit);
void AI_DoUnits(char civ);

////////////////////////////
// Settler Methods /////////
////////////////////////////
void AutomateSettler(char civ, char unit);
void SettlerAction(char num, char civ, bool canBuildCity, bool canBuildRoad, bool canIrrigate, bool canMine, bool i);
bool CanBuildCity(char index, char civ);
bool CanBuildRoad(char index, char civ);
bool CanIrrigate(char index, char civ);
bool CanMine(char index, char civ);

#else

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CreateUnit /////////////////////////////////////////////////////////////////////////////////////////////////////
// creates an individual unit with given variables ////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CreateUnit(char i, char *name, char pic, char atk, char def, char move, int cost, char area, char transport, char preq, char obsolete)
{
	strcpy(_units[i].name, name);
	_units[i].pic = pic;
	_units[i].atk = atk;
	_units[i].def = def;
	_units[i].moveMAX = move;
	_units[i].cost = cost * COST_CONST;
	_units[i].area = area;
	_units[i].transport = transport;
	_units[i].preq = preq;
	_units[i].obsolete = obsolete;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CreateUnits ////////////////////////////////////////////////////////////////////////////////////////////////////
// creates all the units in the _units array //////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CreateUnits()
{
	CreateUnit(0,  "Settler", 			0, 0,  1,  1, 4,  1, 0, -1, -1);
	CreateUnit(1,  "Warrior", 			1, 1,  1,  1, 1,  1, 0, -1, 29);
	CreateUnit(2,  "Pikeman", 			2, 1,  3,  1, 3,  1, 0, 29, 35);
	CreateUnit(3,  "Horseman", 			3, 2,  1,  2, 2,  1, 0, 36, 11);
	CreateUnit(4,  "Knight", 				3, 4,  2,  2, 5,  1, 0, 11, -1);
	CreateUnit(5,  "Archer", 				4, 3,  1,  1, 3,  1, 0, 86, 35);
	CreateUnit(6,  "Swordsman", 		5, 4,  2,  1, 4,  1, 0, 39, 35);
	CreateUnit(7,  "Rifleman", 			6, 5,  4,  1, 4,  1, 0, 35, 17);
	CreateUnit(8,  "Infantry", 			6, 6,  6,  1, 6,  1, 0, 17, -1);
	CreateUnit(9,  "Catapult", 			7, 6,  1,  1, 4,  1, 0, 49, 51);
	CreateUnit(10, "Cannon", 				7, 8,  1,  1, 5,  1, 0, 51, -1);
	CreateUnit(11, "Tank", 					8, 10, 5,  2, 8,  1, 0, 48, 53);
	CreateUnit(12, "Armor", 				8, 12, 5,  3, 10, 1, 0, 53, -1);
	CreateUnit(13, "Mech Infantry", 8, 7,  8,  3, 9,  1, 0, 16, -1);
	CreateUnit(14, "Galley", 				9, 1,  1,  3, 4,  2, 2, 46, 57);
	CreateUnit(15, "Galleon", 			9, 2,  2,  4, 4,  2, 6, 57, 48);
	CreateUnit(16, "Battleship", 		9, 12, 12, 4, 16, 2, 0, 48, -1);
	CreateUnit(17, "Fighter", 			10, 5, 4,  5, 7,  3, 0, 30, -1);
	CreateUnit(18, "Bomber", 				11,12, 1,  4, 12, 3, 0,  0, -1);
}

#endif // !INSTALL

#endif
